package com.muyu.controller;

import com.muyu.api.model.response.ResultResponse;
import com.muyu.model.dto.GetDBInfoByPageDTO;
import com.muyu.model.dto.GetDBInfoDTO;
import com.muyu.service.DBService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @ClassName: DBController
 * @Author: Zirun.Xin
 * @Date: 2025/4/16 下午4:28
 * @Version: 1.0
 * @Description: 数据库控制层
 */
@RestController
@RequiredArgsConstructor
@RequestMapping(value = "/api/v1/db")
public class DBController {

    /**
     * 数据库业务层
     */
    private final DBService dbService;

    /**
     * 获取数据库信息
     * @param getDBInfoDTO 请求体数据传输对象
     * @return 响应结果集
     */
    @PostMapping(value = "/get-db-info")
    public ResultResponse<List<Map<String, String>>> getDBInfo(@RequestBody GetDBInfoDTO getDBInfoDTO) {
        return ResultResponse.ok(dbService.getDBInfo(getDBInfoDTO));
    }

    /**
     * 获取数据库分页信息
     * @param getDBInfoByPageDTO 请求体数据传输对象
     * @return 响应结果集
     */
    @PostMapping(value = "/get-db-info-by-page")
    public ResultResponse<Map<String, Object>> getDBInfoByPage(@RequestBody GetDBInfoByPageDTO getDBInfoByPageDTO) {
        return ResultResponse.ok(dbService.getDBInfoByPage(getDBInfoByPageDTO));
    }
}
